#pragma once

#include <AVUINameScope.h>

namespace AVUI {

typedef ItemStructList< TRefCountedPtr<DependencyObject> > DependencyObjectList;
class ProvideValueServiceProvider;

class TemplateNameScope : public Object, public INameScope
{
public:
    DECLARE_ELEMENT(TemplateNameScope, Object);

    TemplateNameScope(DependencyObject* pTemplatedParent) : m_pTemplatedParent(pTemplatedParent), m_isTemplatedParentAnFE(true) { }
    TemplateNameScope(DependencyObject* pTemplatedParent, DependencyObjectList* pAffectedChildren, UncommonField<HybridDictionary>* pTemplatedNonFeChildrenField, FrameworkTemplate* pFrameworkTemplate);


    virtual Object* FindName(String* pName) AVUI_OVERRIDE;
    virtual void RegisterName(String* pName, Object* pObject) AVUI_OVERRIDE;
    virtual void UnregisterName(String* pName) AVUI_OVERRIDE { };
    virtual Object* get_Object() AVUI_OVERRIDE { return this; }

private:
    void SetTemplateParentValues(String* pName, Object* pElement);

    TRefCountedPtr<DependencyObjectList> m_pAffectedChildren;
    TRefCountedPtr<FrameworkTemplate> m_pFrameworkTemplate;
    bool m_isTemplatedParentAnFE;
    TRefCountedPtr<HybridDictionary> m_pNameMap;
    TRefCountedPtr<ProvideValueServiceProvider> m_pProvideValueServiceProvider;
    static UncommonField<HybridDictionary>* m_pTemplatedNonFeChildrenField;
    TWeakPtr<DependencyObject> m_pTemplatedParent;
};

};
